package com.jt.viewdemo;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import androidx.annotation.Nullable;

/**
 * 审核进度条
 * 根据style传递当前的使用场景，每个场景对应一套函数方法，然后根据代码重复量进行抽取
 */
public class ReviewProcessView extends LinearLayout {

    public SeekBar mSeekBar;
    public Context mcontext;
    public String styleType = "0";
    public RelativeLayout rlModuleReviewProcess;
    public int rlModuleWidth, rlModuleHeight, ivModuleHintWidth, ivModuleHintHeight;
    public int width, height;
    public Bitmap bitmap;
    private Paint paint;

    public ReviewProcessView(Context context) {
        super(context);
        this.mcontext = context;
        init();
    }

    public ReviewProcessView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mcontext = context;
        init();
    }

    public ReviewProcessView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mcontext = context;
        initTypeArray(context, attrs);
        init();
    }

    public ReviewProcessView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.mcontext = context;
        init();
    }

    public void initTypeArray(Context context, AttributeSet attrs) {
        TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.style_review_process_view);
        styleType = mTypedArray.getString(R.styleable.style_review_process_view_view_type);

        mTypedArray.recycle();
    }

    /**
     * 传递当前展示type
     */
    public void setStyleType(String styleType) {
        this.styleType = styleType;
    }

    @SuppressLint("NewApi")
    public void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_review_process, this);
        mSeekBar = findViewById(R.id.sbModuleReviewProcess);

        mSeekBar.setClickable(false);
        mSeekBar.setEnabled(false);
        mSeekBar.setSelected(false);
        mSeekBar.setFocusable(false);

        //        @SuppressLint("UseCompatLoadingForDrawables") Drawable drawable = getResources().getDrawable(R.drawable.icon_module_seekbar_before);
        //        mSeekBar.setThumb(drawable);
        mSeekBar.setProgress(75);

        rlModuleReviewProcess = findViewById(R.id.rlModuleReviewProcess);


        paint = new Paint();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(widthMeasureSpec);

        rlModuleWidth = rlModuleReviewProcess.getWidth();
        rlModuleHeight = rlModuleReviewProcess.getHeight();

        setMeasuredDimension(width, height);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        width = getWidth();
        height = getHeight();
        LogUtil.d("控件宽高 width-->" + width + " height-->" + height);
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_module_seekbar_after);
        canvas.drawBitmap(bitmap, width / 4 - (bitmap.getWidth()) / 2, height / 2, paint);

    }


}
